<?php
session_start();
if($_SESSION["islogin"]!=='igiveyouthepower'){
echo "<script language=JavaScript>\r\n";
echo "alert('请先登录!');\r\n";
echo "location.href='index.php'\r\n";
echo "</script>";
}else{
require_once('config.php');
?>
<?php
$conn = mysqli_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd,$cfg_dbname);
$mquery="select * from ph_products where user_name='".$_SESSION["managername"]."'";
$mresult=mysqli_query($conn,$mquery);
$uquery="select * from ph_admin where admin='".$_SESSION["managername"]."'";
$uresult=mysqli_query($conn,$uquery);
$rowuser = mysqli_fetch_array($uresult);
 // 单位自动转换函数
 function getRealSize($size)
 { 
  $kb = 1024;   // Kilobyte
  return round($size/$kb,2);
 }
 $realsize=0;
 while($row=mysqli_fetch_array($mresult)){
   $imgresult=mysqli_query($conn,"select * from ph_img where id in(select imgid from(select imgid from ph_proimg where proid='".$row["ID"]."') t order by id asc);");
   while($rowimg=mysqli_fetch_array($imgresult)){
     if(file_exists($_SERVER['DOCUMENT_ROOT'].$rowimg["imgpath"])){
	    $realsize+=filesize($_SERVER['DOCUMENT_ROOT'].$rowimg["imgpath"]);
	 }
   }
 }
 //echo getRealSize(getDirSize($_SERVER['DOCUMENT_ROOT'].'/files/1'));
$newsize=getRealSize($realsize);
$sql = "update ph_admin set currenthostsize='".$newsize."' where id='".$rowuser["ID"]."'";
mysqli_query($conn,$sql);
echo "<script language=JavaScript>\r\n";
echo "location.href='/main.php'\r\n";
echo "</script>";
}
?>